package com.doge.walknovel.business.home.genres.rank

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.wnpro.R
import com.doge.walknovel.api.model.NovelInfo
import com.doge.walknovel.core.base.adapters.AdapterCallback
import com.doge.walknovel.core.base.adapters.ITEM_CLICKED
import com.doge.wnpro.databinding.CellRankCellBinding
import com.doge.walknovel.utils.*

class RankCellViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellRankCellBinding = CellRankCellBinding.inflate(
        LayoutInflater.from(parent.context), parent, false),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        itemView.setOnClickCallback {
            callback.invoke(ITEM_CLICKED, itemView.tag)
        }
    }

    fun bind(item: NovelInfo, position: Int) {
        itemView.tag = item
        binding.cover.load(
            item.coverUrl,
            R.drawable.shape_f7f7f7_4,
            transformation = RoundedCorners4,
            width = 76.dp,
            height = 108.dp,
        )
        binding.title.text = item.title
        binding.desc.text = item.description.html
        binding.author.text = item.author
        binding.pos.text = (position + 1).toString()
    }
}